package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import vo.ContactVO;
import vo.StudentVO;

@Entity
public class Student implements Serializable, IEntity {

    @Id
    private String username;
    private String name;
    private String lastName;
    private String password;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date birthDate;
    private String career;
    @OneToOne
    private Wallet wallet;
    @OneToOne(cascade = CascadeType.ALL)
    private Calendar calendar;
    private String activeUser;
    @OneToMany(mappedBy = "student")
    private List<Contact> contacts;
    private boolean administrator;

    public StudentVO toVo() {
        StudentVO vo = new StudentVO();
        vo.setUsername(getUsername());
        vo.setName(getName());
        vo.setLastName(getLastName());
        vo.setPassword(getPassword());
        vo.setBirthDate(getBirthDate());
        vo.setCareer(getCareer());
        vo.setActiveUser(getActiveUser());
        vo.setAdministrator(isAdministrator());
        if (getWallet() != null) {
            vo.setWalletId(getWallet().getId());
        }
        if (getCalendar() != null) {
            vo.setCalendarId(getCalendar().getId());
        }
        vo.setContacts(contactosToVO());
        return vo;
    }
    
    private List<ContactVO> contactosToVO (){
        List<ContactVO> contactVO = new ArrayList<>();
        for(Contact contact : contacts){
            contactVO.add(contact.toVo());
        }
        return contactVO;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String val) {
        this.name = val;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String val) {
        this.lastName = val;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String val) {
        this.password = val;
    }

    public Date getBirthDate() {
        return this.birthDate;
    }

    public void setBirthDate(Date val) {
        this.birthDate = val;
    }

    public String getCareer() {
        return this.career;
    }

    public void setCareer(String val) {
        this.career = val;
    }

    public Wallet getWallet() {
        return this.wallet;
    }

    public void setWallet(Wallet val) {
        this.wallet = val;
    }

    public Calendar getCalendar() {
        return this.calendar;
    }

    public void setCalendar(Calendar val) {
        this.calendar = val;
    }

    public String getActiveUser() {
        return activeUser;
    }

    public void setActiveUser(String usuarioActivo) {
        this.activeUser = usuarioActivo;
    }

    public List<Contact> getContacts() {
        return contacts;
    }

    public void setContacts(List<Contact> contactos) {
        this.contacts = contactos;
    }

    public boolean isAdministrator() {
        return administrator;
    }

    public void setAdministrator(boolean administrator) {
        this.administrator = administrator;
    }
    
}
